home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: nntp.coast.net!torn!news!apollo!saed
- From: saed@engn.uwindsor.ca (Saed Aryan,13325,1100,g)
- Subject: c++.moderated Q : template class as friend
- X-Nntp-Posting-Host: apollo.engn.uwindsor.ca
- Message-ID: <Do0q95.C0o@news.uwindsor.ca>
- Keywords: friend, template
- Sender: news@news.uwindsor.ca (Usenet)
- Reply-To: saed@engn.uwindsor.ca
- Organization: VLSI Research Group - University of Windsor
- Date: Sat, 9 Mar 1996 20:58:17 GMT
-
- Hi all,
-
- magnus@darwin.uchicago.edu (Magnus Nordborg) wrote in c++.moderated :
-
- >How do I accomplish the following? I have a class, baseA, from which I
- >derive
- >class A : public baseA.
- >I also have a template class, baseB, from which I derive
- >class B : public baseB<A>,
- >and B's members need access to the protected members of baseA. In other
- >words, how does one declare a template class to be a "friend" of the class
- >used in the template instantiation?
-
- Well, my code below shows how to do that, and it compiles just fine
- (g++ 2.7.0).
-
- But B is a _derived_ class of the template class. to me
- "In other words" doesn't comply with the class structure you show above.
- What is the role of the base and derived classes in your example?
-
- Did you want the whole template class to be a friend of one template
- instance? If so then the more general question would be:
-
- ---How can one declare a whole template class to be a friend of another
- class (a template instance or any other class)?
-
- This is precisely what I recently asked in this news group:
-
- From saed@engn.uwindsor.ca (Saed Aryan,13325,1100,g)
- Subject: [Q] how declare a Template class as a friend
- Date: Thu, 7 Mar 1996 22:51:36 GMT
-
- and I have no suggestions yet...
-
- Aryan.
-
- //---code begins
- class baseA
- {
- friend class derB;
- protected: int x;
- };
-
- class derA : public baseA {};
-
- template <class T> class baseB {};
-
- class derB : public baseB<derA>
- {
- derBMethod(baseA baseAObj){ baseAObj.x = 1; };
- };
- //---code ends
-
-
-
-